import 'package:flutter/material.dart';
import 'package:flutter_house_manager/pages/Home/index.dart';
import 'package:flutter_house_manager/pages/Mine/index.dart';

class TabsPage extends StatefulWidget {
  const TabsPage({super.key});

  @override
  State<TabsPage> createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  final List _tabList = [
    {
      "label": '首页',
      "icon": "assets/tabs/home_default.png",
      "active_icon": "assets/tabs/home_active.png"
    },
    {
      "label": '我的',
      "icon": "assets/tabs/my_default.png",
      "active_icon": "assets/tabs/my_active.png"
    }
  ];

  List<BottomNavigationBarItem> getTabsBar() {
    List<BottomNavigationBarItem> tabsBar = [];
    for (var item in _tabList) {
      tabsBar.add(BottomNavigationBarItem(
        icon: Image.asset(
          item["icon"],
          width: 30,
          height: 30,
        ),
        activeIcon: Image.asset(
          item["active_icon"],
          width: 30,
          height: 30,
        ),
        label: item["label"],
      ));
    }
    return tabsBar;
  }

  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: IndexedStack(
        index: _currentIndex,
        children: const [
          HomeView(),
          MineView(),
        ],
      )),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        selectedItemColor: const Color.fromARGB(255, 1, 53, 71),
        onTap: (index) {
          _currentIndex = index;
          setState(() {});
        },
        items: getTabsBar(),
      ),
    );
  }
}
